import { DataTypes, Model } from 'sequelize'
import { sequelize } from '../../connect'
import { findAllValues, findOneRandomValue, findOneValue } from '../../public'

type ModelProps = {
  id: number // 表id
  name: number // 地图
  thing: string // 名称
  type: string // 类型
  x: number // 坐标x
  y: number // 坐标y
  detail: JSON // 详情
}

class map_infor extends Model<ModelProps> {
  public static findAllValues = findAllValues
  public static findOneValue = findOneValue
  public static findOneRandomValue = findOneRandomValue
}

map_infor.init(
  {
    id: {
      type: DataTypes.BIGINT,
      primaryKey: true,
      allowNull: false,
      autoIncrement: true,
      comment: '表id'
    },
    name: {
      type: DataTypes.STRING(50),
      allowNull: false,
      comment: '地图'
    },
    thing: {
      type: DataTypes.STRING(50),
      allowNull: false,
      comment: '名称'
    },
    type: {
      type: DataTypes.STRING(50),
      allowNull: false,
      comment: '类型'
    },
    x: {
      type: DataTypes.INTEGER,
      allowNull: false,
      comment: '坐标x'
    },
    y: {
      type: DataTypes.INTEGER,
      allowNull: false,
      comment: '坐标y'
    },
    detail: {
      type: DataTypes.JSON,
      allowNull: false,
      comment: '详情'
    }
  },
  {
    sequelize,
    tableName: 'map_infor',
    freezeTableName: true,
    createdAt: false,
    updatedAt: false,
    indexes: [
      {
        unique: false,
        fields: ['id']
      }
    ]
  }
)

export { map_infor }
